<template>
  <view class="my-attention">
	  <!-- 公共组件-每个页面必须引入 -->
	  <public-module></public-module>
    <u-sticky bgColor="#fff">
      <!-- <u-subsection :list="list" :current="curNow" @change="sectionChange"  mode="subsection"></u-subsection> -->
      <div style="width:60%;margin:0 auto">
        <u-tabs :list="list" lineColor="#FF5E01" :activeStyle="{color: '#FF5E01'}" @click="sectionChange"
          :scrollable="false" lineWidth="60"></u-tabs>
      </div>

    </u-sticky>
    <div style="padding:32rpx">
      <view v-if='curNow==0'>
        <view v-for="(item,index) in attList" :key="index" @click="toLink('/pages/inquiry/inquiryInfo?inquiryId='+item.inquiryId)">
          <view class="inquiry-goods">
            <view class="inquiry-goods-top">
              <text class="left">{{item.goodsSn}}/{{item.brandName}}/{{item.categoryName}}</text>
              <text class="right">{{item.state | priceState }}</text>
            </view>
            <view class="inquiry-goods-bottom">
              <view class="left">
                <text class="update">最新报价：</text>
                <text class="pirce">{{item.newPrice}}</text>
                <text class="weight" v-if="item.newPrice != ''">/吨</text>
              </view>
              <view class="right">
                <u-button type="text" size="small" @tap="openPopup(item.logId)">取消关注</u-button>
              </view>
            </view>
          </view>
        </view>
        <div style="padding-bottom:40rpx;">
          <u-loadmore :status="status"></u-loadmore>
        </div>
      </view>
      <!-- 厂家 -->
      <view v-if='curNow==1'>
        <view v-for="(item,index) in attList" :key="index" @click="toLink('/pagesUser/business/businessPage?storeId='+item.storeId)">
          <view class="manufactor">
            <view class="manufactor-left">
              <!-- <image class="avatar" :src="avatarUrl || '../../../static/head.png'"></image> -->
              <u-avatar :src="item.storeLogo" shape="circle" size='44'></u-avatar>
            </view>
            <view class="manufactor-right">
              <view class="manufactor-rtop">
                <text class="update">{{item.storeName}}</text>
              </view>
              <view class="manufactor-rbottom">
                <view class="manufactor-rbottoml" style="padding-left:0">
                  主营：{{item.mainBusiness}}
                </view>
                <view class="manufactor-rbottomr" style="width:160rpx">
                  <u-button type="text" size="small" @click="openPopup(item.logId)">取消关注</u-button>
                </view>
              </view>
            </view>
          </view>
        </view>
        <div style="padding-bottom:40rpx;">
          <u-loadmore :status="status"></u-loadmore>
        </div>
      </view>

    </div>

  </view>
</template>

<script>
  import {
    myAttentionList,
    delMyAttention
  } from '@/config/api2.js'
  import toast from '../../uni_modules/uview-ui/libs/config/props/toast'
  const defaultListQuery = {
    "tab": "",
    "pageSize": 10,
    "pageNum": 1
  };
  export default {
    data() {
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        status: 'loadmore',
        count: 0,
        attList: [],
        logid: '',
        list: [{
            name: '询价'
          },
          {
            name: '厂家'
          }
        ],
        curNow: 0
      }
    },
    onLoad() {
      const data = this.curNow == 0 ? 'inquiry' : 'stores';
      this.clearData();
      this.getMyAttentionList(data)
    },
    onReachBottom() {
      if (this.attList.length >= this.count) {
        this.status = 'nomore';
        return;
      }
      this.listQuery.pageNum++
      this.getMyAttentionList()
    },
    methods: {
		toLink(url){
			uni.navigateTo({
			    url:url
			})
		},
      //清除数据
      clearData() {
        this.listQuery.pageNum = 1;
        this.attList = [];
        this.status = 'loadmore';
        this.count = 0;
      },
      sectionChange(e) {
        this.curNow = e.index;
        this.clearData();
        this.getMyAttentionList(e.index == 0 ? 'inquiry' : 'stores')
      },
      getMyAttentionList(tab) {
        const data = JSON.parse(JSON.stringify(this.listQuery))
        data.tab = tab
        myAttentionList(data).then(res => {
          this.count = res.count
          this.attList = this.attList.concat(res.list ? res.list : []);
          if (this.attList.length >= this.count) {
            this.status = 'nomore';
          } else {
            this.status = 'loadmore';
          }
        })
      },
      delMyAttentions(id) {
        delMyAttention({
          logid: id
        }).then(res => {
          uni.showToast({
            title: '操作成功',
            duration: 1000,
            icon: 'none'
          })
          this.showPopup = false;
          this.clearData();
          const data = this.curNow == 0 ? 'inquiry' : 'stores'
          this.getMyAttentionList(data)
        })
      },

      openPopup(id) {
        uni.showModal({
          title: '提示',
          content: '请确认取消关注',
          success: (res) => {
            if (res.confirm) {
              this.delMyAttentions(id)
            } else if (res.cancel) {}
          }
        });
      },

    }
  }
</script>

<style lang="scss" scoped>
  @import '@/style/wmj.scss';
</style>